package br.ufla.pgcc.oomeasures.measures;

import org.eclipse.jdt.core.dom.CompilationUnit;

import br.ufla.pgcc.oomeasures.astvisitors.CommentRatioVisitor;


public class CommentsRatio extends Measure {
	private double value;

	public CommentsRatio() {
		super();
		value = 0d;
		addApplicableGranularity(Granularity.CLASS);
	}

	@Override
	public String getName() {
		return "Comments Ratio";
	}

	@Override
	public String getAcronym() {
		return "CR";
	}

	@Override
	public String getDescription() {
		return "Return the number of [Number of Comments] / [Lines of Code]";
	}

	@Override
	public double getMinValue() {
		return 0;
	}

	@Override
	public double getMaxValue() {
		return 0;
	}

	@Override
	public double getRefValue() {
		return 0;
	}

	@Override
	public <T> void measure(T unit) {

		// Now create the AST for the ICompilationUnits
		CompilationUnit parse = parse(unit);
		CommentRatioVisitor visitor = new CommentRatioVisitor();
		parse.accept(visitor);
		value = visitor.getCommentsRatio(); 
	}

	@Override
	public double getCalculatedValue() { 
		return value;
	}

	@Override
	public void setCalculatedValue(double value) {
		this.value = value; 
	}
}
